package com.tianhui.consignortwofei.mvp.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.other.CommonEvent;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.constant.OrderType;
import com.tianhui.consignortwofei.mvp.model.enty.OrderInfo;
import com.tianhui.consignortwofei.mvp.model.enty.OrderOperateInfo;
import com.tianhui.consignortwofei.other.EventWhat;
import com.tianhui.consignortwofei.pattern.orderOprate.DispatchOperateList;
import com.tianhui.consignortwofei.pattern.orderOprate.IOperateList;
import com.tianhui.consignortwofei.pattern.orderOprate.SourceOperateList;
import com.tianhui.consignortwofei.widget.OrderOperateView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author fgs
 * @date 2020/8/29
 * @description
 **/
public class OrderOperateActivity extends BaseActivity {

    @BindView(R.id.activity_order_operate_topOrderOperateView)
    OrderOperateView mTopOrderOperateView;
    @BindView(R.id.activity_order_operate_bottomOrderOperateView)
    OrderOperateView mBottomOrderOperateView;
    private int type;

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_operate;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public void init() {

        Bundle bundle = getIntent().getExtras();
        if (bundle != null && !bundle.isEmpty()) {
            OrderInfo orderInfo = bundle.getParcelable(KeyValue.KEY_ORDER_INFO);
            type = bundle.getInt(KeyValue.KEY_TYPE);
            IOperateList iOperateList = null;
            if (type == OrderType.TYPE_SOURCE|| type == OrderType.TYPE_SOURCE_DINGJIN) {
                iOperateList = new SourceOperateList();
                getToolbarStatus().setTitle("货源详情");
            } else if (type == OrderType.TYPE_DISPATCH|| type == OrderType.TYPE_DISPATCH_DINGJIN) {
                iOperateList = new DispatchOperateList();
                getToolbarStatus().setTitle("调度详情");
                if (type == OrderType.TYPE_DISPATCH_DINGJIN) {
                    getToolbarStatus().setSubtitle("司机违约");
                    getToolbarStatus().setOnToolbarClickListener(new OnToolbarClickListener() {
                        @Override
                        public void onSubtitleClick() {
                            Bundle bundle = new Bundle();
                            bundle.putParcelable(KeyValue.KEY_ORDER_INFO, orderInfo);
//                            bundle.putInt(KeyValue.KEY_TYPE, mIOrderStatus.getOrderStatusType());
                            openActivity(DriverDefaultActivity.class, bundle);
                        }

                        @Override
                        public void onBackIconClick() {
                            finish();
                        }
                    });
                }
            }
            if (iOperateList != null) {
                mTopOrderOperateView.setOperateInfoList(iOperateList.getTopOperateList(orderInfo));
                mTopOrderOperateView.setCenterOperateInfo(iOperateList.getTopCenterOperateInfo(orderInfo));
                mBottomOrderOperateView.setOperateInfoList(iOperateList.getBottomOperateList(orderInfo));
                mBottomOrderOperateView.setCenterOperateInfo(iOperateList.getBottomCenterOperateInfo(orderInfo));
            }
        }

        mTopOrderOperateView.setOnOrderOperateClickListener(new OrderOperateView.OnOrderOperateClickListener() {
            @Override
            public void onOperateClick(Context context, TextView textView, int position, OrderOperateInfo operateInfo) {
                if (operateInfo != null && operateInfo.iOrderOperate != null)
                    operateInfo.orderInfo.dingJinType=type;
                    operateInfo.iOrderOperate.orderOperate(context, operateInfo);
            }

        });
        mBottomOrderOperateView.setOnOrderOperateClickListener(new OrderOperateView.OnOrderOperateClickListener() {
            @Override
            public void onOperateClick(Context context, TextView textView, int position, OrderOperateInfo operateInfo) {
                if (operateInfo != null && operateInfo.iOrderOperate != null)
                    operateInfo.orderInfo.dingJinType=type;
                    operateInfo.iOrderOperate.orderOperate(context, operateInfo);
            }

        });

    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }


    @OnClick(R.id.activity_order_operate_backImageView)
    public void back() {
        finish();
    }

    @Override
    public void onEvent(CommonEvent event) {
        switch (EventWhat.valueOf(event.getWhat())) {
            case EVENT_OPERATE_ACTIVITY_FINISH:
                finish();
                break;
        }
    }
}
